import http from '@/utils/service';

const API = {
  saveOrder: '/order/saveOrder',
  getUserOrder: '/order/getUserOrder',
  toPay: '/order/toPay',
  refund: '/order/refund',
  getOrder: '/order/getOrder',
  score: '/order/score',
  getOrderById: '/order/getOrderById',
  cancelOrder: '/order/cancelOrder',
  test1: '/order/test1',
  test2: '/order/test2',
  getComplaintOrder: '/order/getComplaintOrder',
};

export interface OrderData {
  couponId: number;
  userDist: number;
  userId: number;
  orderDetail: string;
  seatId: number;
  orderMoney: number;
  datePeriod: string;
  timePeriod: number;
  userRemarks: string;
  paymentManner: string;
  paymentTime: string;
  restaurantId: number;
}

export interface GetUserOrder {
  userId: number;
  current: number;
  size: number;
  sortField: string;
  sortOrder: string;
}

export interface GetOrder {
  masterId: number;
  restaurantId: number;
  current: number;
  size: number;
  sortField: string;
  sortOrder: string;
}

export interface DataType {
  id: number;
  seatName: string;
  orderMoney: number;
  datePeriod: string;
  name: string;
  status: number;
  timePeriod: number;
  createTime: string;
  dishNameList: {
    dishName: string;
    dishNum: number;
  }[];
}

export interface OrderPay {
  id: number;
  orderMoney: number;
  restaurantName: string;
}

export interface OrderScore {
  userId: number;
  restaurantId: number;
  orderId: number;
  restaurantScore: number;
  dishList: {
    dishId: number;
    dishScore: number;
  }[];
}

export const saveOrderAPI = (data: OrderData) =>
  http.post(API.saveOrder, { data });

export const getUserOrderAPI = (data: GetUserOrder) =>
  http.post(API.getUserOrder, { data });

export const toPayAPI = (data: OrderPay) => http.post(API.toPay, { data });

export const refundAPI = (orderId: number) =>
  http.get(API.refund + `?orderId=${orderId}`);

export const getOrderAPI = (data: GetOrder) =>
  http.post(API.getOrder, { data });

export const getOrderByIdAPI = (id: number) =>
  http.get(API.getOrderById + `?orderId=${id}`);
export const scoreAPI = (data: OrderScore) => http.post(API.score, { data });
export const cancelOrderAPI = (id: number) =>
  http.delete(API.cancelOrder + `?orderId=${id}`);
export const test1API = (id: number) => http.get(API.test1 + `?orderId=${id}`);
export const test2API = (id: number) => http.get(API.test2 + `?orderId=${id}`);
export const getComplaintOrderAPI = () => http.get(API.getComplaintOrder);
